#ifndef CONVEX_HULL_HPP
#define CONVEX_HULL_HPP

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/VertexArray.hpp>

#include <SmegTools/Config.h>

#include "Hull.hpp"

#include <SmegTools/Debug/DebugNew.hpp>

namespace smeg {
    namespace light {
        
////////////////////////////////////////////////////////////
/// Represent a Convex Hull
////////////////////////////////////////////////////////////
class ConvexHull : public Hull
{
public:
    ////////////////////////////////////////////////////////////
    /// Is the given hull convex
    ///
    /// \param _VertexArray :   Array of vertices to test
    ///
    /// \return Whether the given array of vertices representes a convex hull
    ///
    ////////////////////////////////////////////////////////////
    static bool                 IsValidConvexHull( const sf::VertexArray& _VertexArray );
    
    ////////////////////////////////////////////////////////////
    /// Default Constructor
    ///
    /// \param _Center :        Center of the hull
    /// \param _fAngleDeg :     Rotation angle
    /// \param _bIsStatic :     Static or dynamic ?
    /// \param _pParent :       Shadow caster parent if any
    ///
    ////////////////////////////////////////////////////////////
                                ConvexHull( const sf::Vector2f& _Center     = sf::Vector2f(), 
                                            float _fAngleDeg                = 0.0f,
                                            bool _bIsStatic                 = false,
                                            ShadowCasterEntity* _pParent    = NULL );
    ////////////////////////////////////////////////////////////
    /// Constructor with a filename to load
    ///
    /// \param _Filename :      Filename to load
    /// \param _Center :        Center of the hull
    /// \param _fAngleDeg :     Rotation angle
    /// \param _bIsStatic :     Static or dynamic ?
    /// \param _pParent :       Shadow caster parent if any
    ///
    ////////////////////////////////////////////////////////////
                                ConvexHull( const std::string& _Filename, 
                                            const sf::Vector2f& _Center     = sf::Vector2f(),
                                            float _fAngleDeg                = 0.0f,
                                            bool _bIsStatic                 = false,
                                            ShadowCasterEntity* _pParent    = NULL );
    ////////////////////////////////////////////////////////////
    /// Constructor with an array of vertices
    ///
    /// \param _VertexArray :   Array of vertices representing the hull
    /// \param _fSizeMultiplier : Size multiplier to apply to the array of vertices
    /// \param _Center :        Center of the hull
    /// \param _fAngleDeg :     Rotation angle
    /// \param _bIsStatic :     Static or dynamic ?
    /// \param _pParent :       Shadow caster parent if any
    ///
    ////////////////////////////////////////////////////////////
                                ConvexHull( const sf::VertexArray& _VertexArray,
                                            float _fSizeMultiplier          = 1.0f,
                                            const sf::Vector2f& _Center     = sf::Vector2f(), 
                                            float _fAngleDeg                = 0.0f,
                                            bool _bIsStatic                 = false,
                                            ShadowCasterEntity* _pParent    = NULL );
    ////////////////////////////////////////////////////////////
    /// Copy Constructor
    ///
    /// \param _Copy :          Convex Hull to copy from
    ///
    ////////////////////////////////////////////////////////////
                                ConvexHull( const ConvexHull& _Copy );
    ////////////////////////////////////////////////////////////
    /// Destructor
    ///
    ////////////////////////////////////////////////////////////
    virtual                     ~ConvexHull();

    CREATE_CLONE_FUNC( ConvexHull, core::BaseEntity );
    
    ////////////////////////////////////////////////////////////
    /// Load a convex hull from a file
    ///
    /// \param _Filename :      File name to load
    ///
    /// \return Whether the loading was successful or not
    ///
    ////////////////////////////////////////////////////////////
    bool                        LoadShape( const std::string& _Filename );
    ////////////////////////////////////////////////////////////
    /// Setup a convex hull from an array of vertices
    ///
    /// \param _VertexArray :   Array of vertices
    /// \param _fSizeMultiplier : Size multiplier to apply to the array of vertices
    ///
    ////////////////////////////////////////////////////////////
    void                        SetupShape( const sf::VertexArray& _VertexArray, float _fSizeMultiplier = 1.0f );
    
    ////////////////////////////////////////////////////////////
    /// Is the given point inside the hull
    ///
    /// \param _Point :         Point to test
    ///
    /// \return Whether the point is inside the hull or not
    ///
    ////////////////////////////////////////////////////////////
    virtual bool                IsPointInHull( const sf::Vector2f& _Point ) const;
};

    } // namespace light
} // namespace smeg

#include <SmegTools/Debug/DebugNewOff.hpp>

#endif // CONVEX_HULL_HPP
